package com.liaoyifan.core.datasource;

import java.util.function.Supplier;

@SuppressWarnings("unused")
public class DataSourceHolder {

    private static final ThreadLocal<Supplier<String>> DATA_SOURCE_HOLDER = new ThreadLocal<>();

    public static void set(String key) {
        DATA_SOURCE_HOLDER.set(() -> key);
    }

    public static String get() {
        Supplier<String> result = DATA_SOURCE_HOLDER.get();
        return result == null ? null : result.get();
    }

    public static void clear() {
        DATA_SOURCE_HOLDER.remove();
    }
}
